package zl.controller;

import cn.hutool.captcha.LineCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class codeController extends HttpServlet {
    @GetMapping("/code")
    public void code(HttpSession session, HttpServletResponse response) throws IOException {
        //创建验证码对象
        LineCaptcha captcha = new LineCaptcha(120, 38, 4, 10);

        //将验证码文本存放在session中
        session.setAttribute("code", captcha.getCode());

        //发送验证码图片到浏览器
        captcha.write(response.getOutputStream());
    }

}